
################################################################################
# Set minimum required version of cmake, project name and compile options
################################################################################
cmake_minimum_required(VERSION 3.8)
project(hardware_interface)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

################################################################################
# Find and load build settings from external packages
################################################################################
find_package(ament_cmake REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)
find_package(turtlesim REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclpy REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(std_srvs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(serial REQUIRED)
find_package(rosidl_default_generators REQUIRED)

find_package(robot_msgs REQUIRED) 

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  # set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  # set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

################################################################################
# Build
################################################################################
include_directories(
  include
)

set(dependencies
  "tf2_ros"
  "tf2"
  "tf2_geometry_msgs"
  "rclcpp"
  "std_msgs"
  "nav_msgs"
  "std_srvs"
  "sensor_msgs"
  "serial"
  "robot_msgs"
  "turtlesim"
)


set(EXEC_NAME 
  "hardware_interface_node")

set(hardware_interface_node_SRCS
  "src/main.cpp"
  "src/hardware_interface.cpp"
  "src/ros_interface.cpp"
)

add_executable(${EXEC_NAME} ${hardware_interface_node_SRCS})
ament_target_dependencies(${EXEC_NAME} ${dependencies})


################################################################################
# Install
################################################################################

install(
  TARGETS ${EXEC_NAME}
  DESTINATION lib/${PROJECT_NAME}
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(
  DIRECTORY launch config
  DESTINATION share/${PROJECT_NAME}
)

################################################################################
# Macro for ament package
################################################################################

# 导出头文件目录
ament_export_include_directories(include)

# 导出依赖的包
ament_export_dependencies(geometry_msgs)
ament_export_dependencies(tf2_geometry_msgs)
ament_export_dependencies(turtlesim)
ament_export_dependencies(nav_msgs)
ament_export_dependencies(rclcpp)
ament_export_dependencies(sensor_msgs)
ament_export_dependencies(std_msgs)
ament_export_dependencies(tf2)
ament_export_dependencies(tf2_ros)
ament_export_dependencies(std_srvs)
ament_export_dependencies(robot_msgs)
ament_export_dependencies(serial)
ament_export_dependencies(rosidl_default_generators)

ament_package()
